package com.holyn.guofang.viewcommon.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.holyn.guofang.R;
import com.holyn.guofang.model.webhttp.wo.UpdateInfoWo;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Holyn on 2017/6/8.
 */

public class UpdateAppDialog extends Dialog {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_version)
    TextView tvVersion;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_percent)
    TextView tvPercent;
    @BindView(R.id.progress)
    ProgressBar progress;
    @BindView(R.id.tv_size)
    TextView tvSize;
    @BindView(R.id.tv_sure)
    TextView tvSure;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;

    private UpdateInfoWo updateInfoWo;

    private DialogInterface.OnClickListener onSureClickListener = null;
    private DialogInterface.OnClickListener onCancelClickListener = null;

    public UpdateAppDialog(@NonNull Context context) {
        super(context, com.holyn.mylibrary.R.style.tran_dialog);
        initView();
    }

    public UpdateAppDialog(@NonNull Context context, DialogInterface.OnClickListener onSureClickListener) {
        super(context, com.holyn.mylibrary.R.style.custom_dialog);
        initView();
        this.onSureClickListener = onSureClickListener;
    }

    public UpdateAppDialog(@NonNull Context context, DialogInterface.OnClickListener onSureClickListener, DialogInterface.OnClickListener onCancelClickListener) {
        super(context, com.holyn.mylibrary.R.style.custom_dialog);
        initView();
        this.onSureClickListener = onSureClickListener;
        this.onCancelClickListener = onCancelClickListener;
    }

    public UpdateAppDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        initView();
    }

    public UpdateAppDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_update_dialog, null);
        setContentView(dialogView);
        ButterKnife.bind(this);

        setCanceledOnTouchOutside(false);
    }

    public OnClickListener getOnSureClickListener() {
        return onSureClickListener;
    }

    public void setOnSureClickListener(OnClickListener onSureClickListener) {
        this.onSureClickListener = onSureClickListener;
    }

    public OnClickListener getOnCancelClickListener() {
        return onCancelClickListener;
    }

    public void setOnCancelClickListener(OnClickListener onCancelClickListener) {
        this.onCancelClickListener = onCancelClickListener;
    }

    @OnClick({R.id.tv_sure, R.id.tv_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_sure:
                if (onSureClickListener != null){
                    onSureClickListener.onClick(UpdateAppDialog.this, 0);
                } else {
                    UpdateAppDialog.this.dismiss();
                }
                break;
            case R.id.tv_cancel:
                if (onCancelClickListener != null){
                    onCancelClickListener.onClick(UpdateAppDialog.this, 1);
                } else {
                    UpdateAppDialog.this.dismiss();
                }
                break;
        }
    }

    public UpdateInfoWo getUpdateInfoWo() {
        return updateInfoWo;
    }

    public void setUpdateInfoWo(UpdateInfoWo updateInfoWo) {
        this.updateInfoWo = updateInfoWo;
    }

    public TextView getTvTitle() {
        return tvTitle;
    }

    public void setTvTitle(String text) {
        this.tvTitle.setText(text);
    }

    public TextView getTvVersion() {
        return tvVersion;
    }

    public void setTvVersion(String text) {
        this.tvVersion.setText(text);
    }

    public TextView getTvContent() {
        return tvContent;
    }

    public void setTvContent(String text) {
        this.tvContent.setText(text);
    }

    public TextView getTvStatus() {
        return tvStatus;
    }

    public void setTvStatus(String text) {
        this.tvStatus.setText(text);
    }

    public TextView getTvPercent() {
        return tvPercent;
    }

    public void setTvPercent(String text) {
        this.tvPercent.setText(text);
    }

    public ProgressBar getProgress() {
        return progress;
    }

    public void setProgressIndeterminate(boolean indeterminate) {
        this.progress.setIndeterminate(indeterminate);
    }

    public void setProgress(int progress) {
        this.progress.setProgress(progress);
    }

    public void setProgressMax(int max) {
        this.progress.setMax(max);
    }

    public TextView getTvSize() {
        return tvSize;
    }

    public void setTvSize(String text) {
        this.tvSize.setText(text);
    }
}
